package com.zx.mobile.service.proxy;

import com.zx.map.service.model.BaseAcctInfoModel;
import com.zx.map.service.model.ConsumeLogModel;
import com.zx.map.service.model.CustAcctLogModel;
import com.zx.map.service.model.EncashLogModel;
import com.zx.map.utils.SUConstants;
import com.zx.mobile.domain.EncashApplyDomain;
import com.zx.mobile.domain.MobileUserDomain;
import com.zx.platform.utils.DateUtils;
import com.zx.platform.utils.PmpUtils;
import org.apache.log4j.Logger;

import java.math.BigDecimal;
import java.util.Date;

public class ConsumeCommonProxy {
	/**
	 * log
	 */
	private static Logger log = Logger.getLogger(ConsumeCommonProxy.class);

	/**
	 * 模型转换
	 * 
	 * @param temp
	 * @param transAmt
	 * @return
	 */
	public static BaseAcctInfoModel transformBaseAcct(BaseAcctInfoModel temp,
			String transAmt) {
		BigDecimal avlAmt = new BigDecimal(temp.getAvlBal().toString());
		BigDecimal frzAmt = new BigDecimal(temp.getFrzBal().toString());
		temp.setFrzBal(frzAmt.add(new BigDecimal(transAmt)).doubleValue());
		temp.setAvlBal(avlAmt.subtract(new BigDecimal(transAmt)).doubleValue());
		return temp;
	}

	/**
	 * 模型转换 转换成账务流水
	 * 
	 * @param baseModel
	 * @param consumeLogModel
	 * @return
	 */
	public static CustAcctLogModel transformCustAcct(
			BaseAcctInfoModel baseModel, ConsumeLogModel consumeLogModel) {
		CustAcctLogModel temp = new CustAcctLogModel();
		temp.setAcctBal(baseModel.getAvlBal());
		temp.setAcctType("B");
		temp.setCreateDate(new Date());
		temp.setCustId(consumeLogModel.getMerchantId());
		temp.setCustSysaccount(consumeLogModel.getMerSysAccount());
		temp.setOrdId(consumeLogModel.getConsumeId());
		temp.setRemark("");
		temp.setTransAmt(consumeLogModel.getAccessTradeAmt());
		temp.setOriginalAmt(consumeLogModel.getAccessTradeAmt());
		temp.setTransType(SUConstants.TRANSTYPE_CONSUME);//消费充值
		return temp;
	}

	/**
	 * 记录取现历史
	 * 
	 * @param user
	 * @param encashApplyDomain
	 * @return
	 */
	public static EncashLogModel transformEncachLog(MobileUserDomain user,
			EncashApplyDomain encashApplyDomain) {
		String encashOrd = PmpUtils.getEncashOrderNum();
		EncashLogModel param = new EncashLogModel();
		param.setAgentId(user.getMerchantInfoDetailModel().getAgentId());
		param.setAgentSysAccount(user.getMerchantInfoDetailModel()
				.getAgentSysAccount());
		param.setCreateDate(new Date());
		param.setEncashAmt(Double.valueOf(encashApplyDomain.getEncashAmt()));
		param.setEncashId(encashOrd);
		param.setEncashStatus("N");
		param.setEncashType(encashApplyDomain.getEncashType());
		param.setMerchantId(user.getMerchantInfoDetailModel().getMerchantId());
		param.setMerSysAccount(user.getMerchantInfoDetailModel()
				.getSysAccount());
		param.setEncashDay(DateUtils.dateToString(new Date(), "yyyyMMdd")); // 增加取现日期
		return param;
	}
}
